package com.java.sort;

import java.util.Random;

/**
 * 选择排序
 * @author 19252
 * @date 2020/7/17
 */
public class SelectSort {

    public static void main(String[] args) {
        SelectSort selectSort = new SelectSort();
        int[] array = new int[]{0, 3, 2, 5, 4};
        Random random = new Random();
        int[] testArray = new int[80000];
        for (int i = 0; i < 80000; i++) {
            testArray[i] = random.nextInt(80000);
        }
        selectSort.sort(array);

        long millis = System.currentTimeMillis();
        selectSort.sort(testArray);
        millis = System.currentTimeMillis() - millis;
        System.out.println("数据排序所需的时间：" + millis + "毫秒");
    }

    /**
     * @param array 需要排序的数组
     */
    public void sort(int[] array){
        int length = array.length;
        int temp;
        for (int i = 0; i < length - 1; i++) {
            for (int j = i; j < length - 1; j++) {
                if (array[i] > array[j + 1]){
                    temp = array[i];
                    array[i] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
//            for (int value: array){
//                System.out.print(value);
//            }
//            System.out.println();
        }
    }
}
